#!/usr/bin/env python
# -*- coding: utf-8 -*-
import configparser
import sys
import os.path
from PyQt5.QtWidgets import QApplication
from libs.constants import *
from libs.utils.icon import new_icon
from libs.window.main_window import MainWindow
from libs.image_format import *


def load_config(config_file='args.ini'):
    config = configparser.ConfigParser()
    project_root = os.path.dirname(os.path.abspath(__file__))
    config_path = os.path.join(project_root, 'config' , config_file)
    config.read(config_path)
    return config

def get_main_app(argv=None):
    """
    Standard boilerplate Qt application code.
    Do everything but app.exec_() -- so that we can test the application in one thread
    """
    if not argv:
        argv = []
    app = QApplication(argv)
    app.setApplicationName(APP_NAME)
    app.setWindowIcon(new_icon("app"))

    config = load_config()
    img_dir = config['dir'].get('image_dir',None)
    class_file = config['dir'].get('class_file', None)

    # Usage : fast_playback.py image classFile saveDir
    win = MainWindow(img_dir,
                     class_file)
    win.show()
    return app, win

if __name__ == '__main__':
    app , _win = get_main_app(sys.argv)
    sys.exit(app.exec_())
